<template>
  <div class="insertuserinfo-container">
    <el-form :label-position="labelPosition" label-width="80px" :model="userInfo">
      <el-form-item label="姓名">
        <el-input v-model="userInfo.username" placeholder="请输入姓名（账号）"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="userInfo.password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="userInfo.email" placeholder="请输入邮箱"></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-input v-model="userInfo.role" placeholder="请设置权限（admin为超级管理员，normal为普通用户）"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="insertUserInfo(userInfo)">提交</el-button>
        <el-button @click="getback">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'InsertUserInfo',
  data () {
    return {
      labelPosition: 'right',
      userInfo: {
        username: '',
        password: '',
        email: '',
        role: ''
      }
    }
  },
  methods: {
    async insertUserInfo (formData) {
      console.log(formData)
      // 如果传递的数据是复杂数据类型（对象），不用加{}
      const res = await this.$api.insertUserInfo(formData)
      console.log(res)
      if (res.data.err_code === 0) {
        this.$notify({
          title: '成功',
          message: res.data.message,
          type: 'success'
        })
        this.$router.replace('/system/home/user')
      }
    },
    getback () {
      this.$router.replace('/system/home/user')
    }
  }
}
</script>

<style lang="less" scoped></style>
